/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mekegi.whoanthro.Sql;

import android.content.ContentValues;
import android.content.Context;
import com.mekegi.whoanthro.Child;
import com.mekegi.whoanthro.Measure;
import com.mekegi.whoanthro.ModelBuilder;
import com.mekegi.whoanthro.R;

/**
 *
 * @author Arsen Abdusalamov
 */
public class MeasureAdapter extends AbstractSqlAdapter {

    protected static int DB_VERSION = 2;
    protected static String[] COLUMNS_TO_TAKE = {
        Measure.KEY_ID,
        Measure.KEY_HEIGHT,
        Measure.KEY_WEIGHT,
        Measure.KEY_GIRTH_HEAD,
        Measure.KEY_CREATED_AT,
        Measure.KEY_FK_CHILD
    };
    protected static int LAYOUT_ID = R.layout.measures;
    protected static int MODEL_KEY_FOR_FACTORY = ModelBuilder.MODEL_MEASURE;
    protected static ContentValues config;

    public MeasureAdapter(Context context) {
        super(context);
    }

    @Override
    protected String getCreateTableSql() {
        return "CREATE TABLE " + getTableName() + "("
            + Measure.KEY_ID + " INTEGER NOT NULL,"
            + Measure.KEY_HEIGHT + " INTEGER,"
            + Measure.KEY_FK_CHILD + " INTEGER,"
            + Measure.KEY_WEIGHT + " INTEGER,"
            + Measure.KEY_GIRTH_HEAD + " INTEGER,"
            + Measure.KEY_CREATED_AT + " INTEGER,"
            + "PRIMARY KEY (" + Measure.KEY_ID + "),"
            //+ "INDEX i" + Measure.KEY_FK_CHILD + " (" + Measure.KEY_ID + "),"
            + "FOREIGN KEY(" + Measure.KEY_FK_CHILD + ") "
            + "REFERENCES " + Child.TABLE_NAME + "(" + Child.KEY_ID + ") ON DELETE CASCADE ON UPDATE CASCADE"
            + ")";
    }

    @Override
    protected ContentValues getConfigMap() {
        if (null == config) {
            config = new ContentValues();
            config.put(KEY_DB_VERSION, DB_VERSION);
            config.put(KEY_LAYOUT_ID, LAYOUT_ID);
            config.put(KEY_MODEL_FOR_FACTORY, MODEL_KEY_FOR_FACTORY);
            config.put(KEY_TABLE_NAME, Measure.TABLE_NAME);
        }
        return config;
    }

    @Override
    protected String[] getColumnsToTake() {
        return COLUMNS_TO_TAKE;
    }
}
